package com.dyb.demo.algorithm.array;

public class InsertSort {
    public static void main(String[] args) {
        int[] array = new int[]{21, 99, 3, 1024, 16};
        sort(array);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            System.out.print("\t");
        }
    }

    public static void sort(int[] array) {
        for (int i = 1; i < array.length; i++) {
            int temp = array[i];
            for (int j = i - 1; j >= 0; j--) {
                if (temp < array[j]) {
                    array[j + 1] = array[j];
                    array[j] = temp;
                }
            }
        }
    }
}
